package fr.liglab.adele.icasa.house.abstraction;

import fr.liglab.adele.icasa.device.presence.PresenceSensor;
import fr.liglab.adele.icasa.device.presence.Speaker;
import fr.liglab.adele.icasa.house.factory.dao.GenesisDeviceDAO;
import fr.liglab.adele.icasa.house.util.RoomAdvertiseListener;

public abstract class SoundRoom extends AbstractRoom {

	private RoomAdvertiseListener parentNotification;
	
	public SoundRoom(){
		getDevices().add(new GenesisDeviceDAO("sound",Speaker.class));
		getDevices().add(new GenesisDeviceDAO("sensor",PresenceSensor.class,this));
	}
	
	public void addListener(RoomAdvertiseListener listener) {
		parentNotification=listener;
	}
	
	public void notifyDeviceEvent() {
			
			if(getSensor().getSensedPresence()){
				this.getSoundDevice().turnon();
				if(parentNotification!=null)
					parentNotification.onSoundRoomActivate(this,getSoundDevice());
			}else{
				this.getSoundDevice().turnoff();
				if(parentNotification!=null)
					parentNotification.onSoundRoomDeactivate(this,getSoundDevice());
			}
	
	}
	
	public abstract PresenceSensor getSensor();
	
	public abstract Speaker getSoundDevice();

}


